//
//  DetailViewController.swift
//  Presidents
//
//  Created by 鲁万财 on 15/7/28.
//  Copyright (c) 2015年 鲁万财. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController,UISplitViewControllerDelegate,UIPopoverControllerDelegate {

    @IBOutlet weak var detailDescriptionLabel: UILabel!;
    private var masterPopoverController: UIPopoverController!;


    var detailItem: AnyObject? {
        didSet {
            // Update the view.
            self.configureView();
            if(self.masterPopoverController != nil) {
                self.masterPopoverController.dismissPopoverAnimated(true);
            }
        }
    }

    func configureView() {
        // Update the user interface for the detail item.
        if let detail: AnyObject = self.detailItem {
            if let label = self.detailDescriptionLabel {
                label.text = detail.description as String;
                
                NSLog("%@", detail.description as String);
            }
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad();
        // Do any additional setup after loading the view, typically from a nib.
        self.configureView();
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning();
        // Dispose of any resources that can be recreated.
    }

    func splitViewController(svc: UISplitViewController, willHideViewController aViewController: UIViewController, withBarButtonItem barButtonItem: UIBarButtonItem, forPopoverController pc: UIPopoverController) {
        barButtonItem.title = NSLocalizedString("Master", comment: "Master");
        self.navigationItem.setLeftBarButtonItem(barButtonItem, animated: true);
        self.masterPopoverController = pc;
    }
    
    func splitViewController(svc: UISplitViewController, willShowViewController aViewController: UIViewController, invalidatingBarButtonItem barButtonItem: UIBarButtonItem) {
        self.navigationItem.setLeftBarButtonItem(nil, animated: true);
        self.masterPopoverController = nil;
    }

}

